<?xml version="1.0" encoding="UTF-8"?>
<xsl:stylesheet version="2.0"
    xmlns:zfiml="http://ZF-IML.org"
    xmlns:xsl="http://www.w3.org/1999/XSL/Transform" 
    xmlns:xs="http://www.w3.org/2001/XMLSchema" 
    xmlns:aorml="http://AOR-AppML.org">
    <xsl:output method="xml" />
    <xsl:output name="php" method="text" />
    <xsl:variable name="break"><xsl:text>
</xsl:text></xsl:variable>
    <xsl:variable name="tab"><xsl:text>    </xsl:text></xsl:variable>
    <!--path for helium: /srv/www/webapps/oryx/test/ -->
    <!-- path on local windows: file:///Program Files/apache-tomcat6/webapps/oryx/test/ -->
    <xsl:variable name="filepath"><xsl:text></xsl:text></xsl:variable>
    <xsl:function name="aorml:upperFirst" as="xs:string?">
        <xsl:param name="trans" as="xs:string?"></xsl:param>
        <xsl:sequence select="concat(upper-case(substring($trans,1,1)),substring($trans,2))"/>
    </xsl:function>
    <xsl:function name="aorml:lowerFirst" as="xs:string?">
        <xsl:param name="trans" as="xs:string?"></xsl:param>
        <xsl:sequence select="concat(lower-case(substring($trans,1,1)),substring($trans,2))"/>
    </xsl:function>
    <xsl:template match="/">
        <xsl:call-template name="generateZendDbCode" />
        <xsl:call-template name="generateZendControllers" />
        <xsl:call-template name="generateZendViews" />
        <xsl:call-template name="generateZendForms" />        
    </xsl:template>  
    
    
    
    <xsl:template name="generateZendDbCode">
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType">
        <!-- generate DbTable -->
            <xsl:result-document href="{$filepath}application/models/DbTable/{@name}Tbl.php" format="php">
                <xsl:text>&lt;?php</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>class Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>Tbl extends Zend_Db_Table_Abstract</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_name = '</xsl:text><xsl:value-of select="@name"/><xsl:text>';</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_primary = Array(</xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>'</xsl:text>
                    <xsl:if test="position() != last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>'</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                    <xsl:text>'</xsl:text>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_sequence = false;</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_rowClass = 'Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text>';</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_referenceMap = array(</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or (@upperMultiplicity = '1'))and(not(@derived) or (@derived='false'))]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>' => array(</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'columns' => '</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>                    
                    <xsl:text>', </xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'refTableClass' => 'Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="@type"></xsl:value-of>
                    <xsl:text>Tbl', </xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'refColumn' => '</xsl:text>
                    <xsl:value-of select="$refKey"></xsl:value-of>
                    <xsl:text>' ),</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:call-template name="getReferenceMapFromSuper">
                        <xsl:with-param name="objectType" select="@superType"/>
                        <xsl:with-param name="directSuperType" select="@superType"/>
                    </xsl:call-template>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
                
                <xsl:text>public function get</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                <xsl:text>Object(</xsl:text>      
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)" />
                    <xsl:if test="position() != last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>$</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$t = $this->find(</xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)" />
                    <xsl:if test="position() != last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>$</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>return $t[0];</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="$break"></xsl:value-of>
                <xsl:value-of select="concat($break,$tab)" />
                
                <xsl:for-each select="zfiml:EnumerationProperty">
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>Options() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$options = array(</xsl:text>
                    
                    <xsl:for-each select="zfiml:EnumerationLiteral">
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>'</xsl:text>
                        <xsl:value-of select="@value"></xsl:value-of>
                        <xsl:value-of>', </xsl:value-of>                        
                    </xsl:for-each>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $options;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="$break"></xsl:value-of>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
                <xsl:value-of select="$break" />
                <xsl:text>}</xsl:text>                
            </xsl:result-document>
        <!-- generate DbTableRow -->
            <xsl:result-document href="{$filepath}application/models/DbTable/{@name}.php" format="php">
                <xsl:text>&lt;?php</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>class Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text> extends Zend_Db_Table_Row_Abstract</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:for-each select="zfiml:Attribute|zfiml:EnumerationProperty">
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $this-></xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                <!-- set -->
                    <xsl:text>public function set</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text>) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <!-- if the attribute is not mandatory set empty value to NULL -->
                    <xsl:if test="not(@lowerMultiplicity) or @lowerMultiplicity='0'">
                        <xsl:text>if(!isset($</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>)or(''==$</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>)){</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>$this-></xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text> = null;</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>return;</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>}</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                <!-- add Validators -->
                    <!-- add Validator-Chain to add arbitary validators -->
                    <xsl:text>$validatorChain = new Zend_Validate();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <!-- if the attribute is mandatory add Validator -->
                    <xsl:if test="not(not(@lowerMultiplicity) or @lowerMultiplicity='0')">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_NotEmpty(Zend_Validate_NotEmpty::STRING + Zend_Validate_NotEmpty::SPACE + Zend_Validate_NotEmpty::NULL));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if @minValue add Validator -->
                    <xsl:if test="@minValue">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_GreaterThan(array('min' => </xsl:text>
                        <xsl:value-of select="@minValue" />
                        <xsl:text>)));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if @minValue add Validator -->
                    <xsl:if test="@maxValue">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_LessThan(array('max' => </xsl:text>
                        <xsl:value-of select="@maxValue" />
                        <xsl:text>)));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Date add Validator -->
                    <xsl:if test="@type='Date'">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_Date());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Float add Validator -->
                    <xsl:if test="@type='Float'">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_Float());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Integer add Validator -->
                    <xsl:if test="@type='Integer'">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_Int());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='Email'">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_EmailAddress(
                        Zend_Validate_Hostname::ALLOW_DNS ));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='URL'">
                        <xsl:text>$validatorChain->addValidator(new Zend_Validate_Callback(array('Zend_Uri', 'check')));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='Tel'">
                        <xsl:text>$validatorChain->addValidator(new WebAOR_Validate_Tel());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='Time'">
                        <xsl:text>$validatorChain->addValidator(new WebAOR_Validate_Time());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='DateTime'">
                        <xsl:text>$validatorChain->addValidator(new WebAOR_Validate_Datetime());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- if type of attribute is Email add Validator -->
                    <xsl:if test="@type='Boolean'">
                        <xsl:text>$validatorChain->addValidator(new WebAOR_Validate_Boolean());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- throw exception if validation fails -->
                    <xsl:text>if (!$validatorChain->isValid($</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text>))</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>throw new Exception('Validation failed! '.implode(', ' , $validatorChain->getMessages()));</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text> = $</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
                <xsl:variable name="className" select="@name" />
                
            <!-- functions for handle ManyToMany Associations -->
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:variable name="domainRole">
                        <xsl:call-template name="getDomainRole">
                            <xsl:with-param name="association" select="@viaManyToManyAssociation"></xsl:with-param>
                            <xsl:with-param name="name" select="@name"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                <!-- get -->    
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>s() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$rowset = </xsl:text>
                    <xsl:text>$this->findManyToManyRowset('Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="@type"></xsl:value-of>
                    <xsl:text>Tbl' , 'Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="@viaManyToManyAssociation"></xsl:value-of>
                    <xsl:text>Tbl');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$res = array();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>foreach($rowset as $row) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$res[] = $row;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $res;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                <!-- add -->   
                        <xsl:text>public function add</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                        <xsl:text>($</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text>) {</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        
                        <xsl:text>if (!isset($</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text>) or !($</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text> instanceof Application_Model_DbTable_</xsl:text>
                        <xsl:value-of select="@type"/>
                        <xsl:text>)) { throw new Exception('Invalid </xsl:text>
                        <xsl:value-of select="@type"/>
                        <xsl:text>.');    }</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>foreach($this->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)" />
                        <xsl:text>s() as $</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>) {</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>if($</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>-&gt;get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst($refKey)" />
                        <xsl:text>() == </xsl:text>
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text>-&gt;get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst($refKey)" />
                        <xsl:text>() ) {</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                        <xsl:text>throw new Exception('</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)" />
                        <xsl:text> already set!'); </xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>}</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>}</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@viaManyToManyAssociation)" />
                        <xsl:text> = new Application_Model_DbTable_</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@viaManyToManyAssociation)" />
                        <xsl:text>Tbl();</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$row = $</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@viaManyToManyAssociation)" />
                        <xsl:text>-&gt;createRow();</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$row-></xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:text> = $</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)" />
                        <xsl:text>-&gt;get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst($refKey)" />
                        <xsl:text>(); </xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$row-></xsl:text>
                        <xsl:value-of select="$domainRole"/>
                        <xsl:text> = $this->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(../zfiml:Attribute[@isStandardID='true']/@name)"/>
                        <xsl:text>();</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$row->save();</xsl:text>
                        <xsl:value-of select="concat($break,$tab)" />
                        <xsl:text>}</xsl:text>
                        <xsl:value-of select="concat($break,$tab)" />
                <!-- remove -->     
                        <xsl:text>public function remove</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                        <xsl:text>($</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text>) {</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@viaManyToManyAssociation)" />
                        <xsl:text> = new Application_Model_DbTable_</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@viaManyToManyAssociation)" />
                        <xsl:text>Tbl();</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$where = array('</xsl:text>
                        <xsl:value-of select="$domainRole"/>
                        <xsl:text> = ?' =&gt; $this->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(../zfiml:Attribute[@isStandardID='true']/@name)"/>
                        <xsl:text>(), '</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:text> = ?' =&gt; $</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@type)"/>
                        <xsl:text>->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst($refKey)"/>
                        <xsl:text>());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@viaManyToManyAssociation)" />
                        <xsl:text>->delete($where);</xsl:text>  
                        <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
                
                
            <!-- functions for handle non-functional association ends -->
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[not(@viaManyToManyAssociation) 
                                        and @upperMultiplicity='unbounded']">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    
                <!-- get -->
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>s() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$rowset = $this->findDependentRowset('Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"></xsl:value-of>
                    <xsl:text>Tbl'</xsl:text>
                    <xsl:if test="@inverseRoleName">
                        <xsl:text>, '</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@inverseRoleName)" />
                        <xsl:text>'</xsl:text>
                    </xsl:if>
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$res = array();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>foreach($rowset as $row) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$res[] = $row;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $res;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:value-of select="concat($break,$tab)" />
                    
                <!-- add -->
                    <xsl:text>public function add</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>->set</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@inverseRoleName)" />
                    <xsl:if test="not(@inverseRoleName)">
                        <xsl:value-of select="aorml:upperFirst(../@name)" />
                    </xsl:if>
                    <xsl:text>($this);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>->save();</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="$break" />
                    <xsl:value-of select="concat($break,$tab)" />
                    
                    
                <!-- remove -->
                    <xsl:text>public function remove</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>->set</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@inverseRoleName)" />
                    <xsl:if test="not(@inverseRoleName)">
                        <xsl:value-of select="aorml:upperFirst(../@name)" />
                    </xsl:if>
                    <xsl:text>(null);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>->save();</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each> 
                
                
                <!-- functions for handle functional association ends -->
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                 <!-- get -->
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $this->findParentRow('Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"></xsl:value-of>
                    <xsl:text>Tbl' , '</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    
                <!-- set -->
                    <xsl:text>public function set</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"></xsl:value-of>
                    <xsl:text>) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>if($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"></xsl:value-of>
                    <xsl:text>==null) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"></xsl:value-of>
                    <xsl:text> = null;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>} else {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"></xsl:value-of>
                    <xsl:text> = $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"></xsl:value-of>
                    <xsl:text>->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)"></xsl:value-of>
                    <xsl:text>();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    
                </xsl:for-each>
                
                <!-- as derived marked functional and inverse-functional association-end -->
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (@derived = 'true')]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                 <!-- get -->
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $this->findDependentRowset('Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"></xsl:value-of>
                    <xsl:text>Tbl')->current();</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
                
                <!-- get super-object -->
                <xsl:if test="@superType">
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@superType)"></xsl:value-of>
                    <xsl:text>() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $this->findParentRow('Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@superType)"></xsl:value-of>
                    <xsl:text>Tbl', '</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@superType)"></xsl:value-of>
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:if>
                
                <!-- getter and setter for key generated from super -->
                <xsl:if test="@superType">
                    <xsl:variable name="superKey">
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>public function get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($superKey)"></xsl:value-of>
                    <xsl:text>() {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>return $this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst($superKey)"></xsl:value-of>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    
                    <xsl:text>public function set</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($superKey)"></xsl:value-of>
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst($superKey)"></xsl:value-of>
                    <xsl:text>) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst($superKey)"></xsl:value-of>
                    <xsl:text>= $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst($superKey)"></xsl:value-of>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:if>
                <xsl:value-of select="$break" />   
                <xsl:text>}</xsl:text>                
            </xsl:result-document>
        </xsl:for-each>
        <!-- generate Association Tables -->
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ManyToManyAssociation">
        <!-- generate DbTable -->
            <xsl:result-document href="{$filepath}application/models/DbTable/{@name}Tbl.php" format="php">
                <xsl:text>&lt;?php</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>class Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>Tbl extends Zend_Db_Table_Abstract</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_name = '</xsl:text><xsl:value-of select="@name"/><xsl:text>';</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_primary = Array(</xsl:text>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty">
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>'</xsl:text>
                    <xsl:if test="position() != last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>
                </xsl:for-each>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_sequence = false;</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $_referenceMap = array(</xsl:text>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>' => array(</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'columns' => '</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>                    
                    <xsl:text>', 'refTableClass' => 'Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="@type"></xsl:value-of>
                    <xsl:text>Tbl', 'refColumn' => '</xsl:text>
                    <xsl:value-of select="$refKey"></xsl:value-of>
                    <xsl:text>' ),</xsl:text>
                </xsl:for-each>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>);</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>}</xsl:text>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template name="generateZendControllers">
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType">
            <xsl:variable name="className" select="@name" />
            <xsl:result-document href="{$filepath}application/controllers/{@name}Controller.php" format="php">
                <xsl:text>&lt;?php</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>class </xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>Controller extends Zend_Controller_Action</xsl:text>            
                <xsl:value-of select="$break" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>public function init()</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>/** Initialize action controller here */</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <!-- init used table-classes -->
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                    | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"/>
                    <xsl:text>Tbl();</xsl:text>                    
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"/>
                    <xsl:text>Tbl();</xsl:text>                    
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:call-template name="getSuperTableObjects">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
            
            <!-- IndexController -->
                <xsl:text>public function indexAction()</xsl:text>            
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->title = "</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>";</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->headTitle($this->view->title);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$</xsl:text>            
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>Tbl();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view-></xsl:text>            
                <xsl:value-of select="@name" />
                <xsl:text> = $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>Tbl->fetchAll();</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}//index</xsl:text>            
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
                
            <!-- AddController -->
                <xsl:text>public function addAction()</xsl:text>            
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)"/>
                <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)"/>
                <xsl:text>Tbl();</xsl:text>
                <xsl:value-of select="$break" />                
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)"/>
                <xsl:text> = $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)"/>
                <xsl:text>Tbl-&gt;createRow();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:if test="@superType">
                    <xsl:call-template name="getRowsFromSuper">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->title = "Add new </xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>";</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->headTitle($this->view->title);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$form = new Application_Form_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>($</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)"/>
                <xsl:if test="@superType">
                    <xsl:text>, </xsl:text>
                    <xsl:call-template name="getRecParentNameList">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$form->submit->setLabel('Add');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->form = $form;</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab,$tab)" />
                
                <xsl:text>if ($this->getRequest()->isPost()) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$this->update</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)"/>
                <xsl:text>($form, $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)"/>
                <xsl:if test="@superType">
                    <xsl:text>, </xsl:text>
                    <xsl:call-template name="getRecParentNameList">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}//add</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
                
            <!-- EditController -->
                <xsl:text>public function editAction()</xsl:text>            
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:text> = $this->_getParam('</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:text>', 0);</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:for-each>
                    <xsl:if test="@superType">
                        <xsl:text>$</xsl:text>
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                        <xsl:text> = $this->_getParam('</xsl:text>
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                        <xsl:text>', 0);</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"/>
                    <xsl:text>Tbl();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text> = </xsl:text>
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text>Tbl-&gt;get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"/>
                    <xsl:text>Object(</xsl:text>
                    <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:if test="position() != last()">
                            <xsl:text>, </xsl:text>
                        </xsl:if>
                    </xsl:for-each>
                    <xsl:if test="@superType">
                        <xsl:text>$</xsl:text>
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                    </xsl:if>
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:if test="@superType">
                        <xsl:call-template name="getRelatedSuperObjects">
                            <xsl:with-param name="objectType" select="@superType" />
                            <xsl:with-param name="subType" select="@name" />
                        </xsl:call-template>
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <xsl:text>$this->view->title = "Edit </xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>";</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->view->headTitle($this->view->title);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$form = new Application_Form_</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)" />
                    <xsl:if test="@superType">
                        <xsl:text>, </xsl:text>
                        <xsl:call-template name="getRecParentNameList">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                    </xsl:if>
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$form->submit->setLabel('Save');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->view->form = $form;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <xsl:text>if ($this->getRequest()->isPost()) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$this->update</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"/>
                    <xsl:text>($form, $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)" />                   
                    <xsl:if test="@superType">
                        <xsl:text>, </xsl:text>
                        <xsl:call-template name="getRecParentNameList">
                            <xsl:with-param name="objectType" select="@superType" />
                        </xsl:call-template>
                    </xsl:if>
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>} else {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:if test="not(@superType)">
                        <xsl:text>$form->populate($</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)" />
                        <xsl:text>-&gt;toArray());</xsl:text>
                    </xsl:if>
                    <xsl:if test="@superType">
                        <xsl:text>$form->populate(array_merge(</xsl:text>
                            <xsl:call-template name="getSuperArrays" >
                                <xsl:with-param name="objectType" select="@name" />
                            </xsl:call-template>
                        <xsl:text>));</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    
                    <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}//edit</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
                
            <!-- DeleteController -->
                <xsl:text>public function deleteAction()</xsl:text>            
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->title = "Delete from </xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>";</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->view->headTitle($this->view->title);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>if ($this->getRequest()->isPost()) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$del = $this->getRequest()->getPost('del');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>if ($del == 'Yes') {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text> = $this->getRequest()->getPost('</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>$</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text> = $this->getRequest()->getPost('</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                </xsl:if>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$rowset = new Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name"></xsl:value-of>
                <xsl:text>Tbl();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$where = array(</xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>$rowset->getAdapter()->quoteInto('</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text> = ?', </xsl:text>
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>)</xsl:text>
                    <xsl:if test="position() != last()">
                        <xsl:text>, </xsl:text>
                    </xsl:if>               
                </xsl:for-each> 
                <xsl:if test="@superType">
                    <xsl:text>$rowset->getAdapter()->quoteInto('</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text> = ?', </xsl:text>
                    <xsl:text>$</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text>)</xsl:text>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$rowset->delete($where);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$this->_helper->redirector('index');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>} else {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text> = $this->_getParam('</xsl:text>
                    <xsl:value-of select="@name"></xsl:value-of>
                    <xsl:text>', 0);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>$</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text> = $this->_getParam('</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text>', 0);</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                </xsl:if>              
                <xsl:text>$rowset =  new Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>Tbl();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$row = $rowset->fetchRow($rowset->select()</xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>->where('</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text> = ?', $</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>)</xsl:text>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:text>->where('</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text> = ?', $</xsl:text>
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                    <xsl:text>)</xsl:text>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$this->view-></xsl:text>            
                <xsl:value-of select="@name" />
                <xsl:text> = $row;</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>}</xsl:text>            
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}//delete</xsl:text>     
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab)" />
            <!-- update -->
                <xsl:text>protected function update</xsl:text>
                <xsl:value-of select="aorml:upperFirst($className)" />
                <xsl:text>($form, $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />          
                <xsl:if test="@superType">
                    <xsl:text>, </xsl:text>
                    <xsl:call-template name="getRecParentNameList">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>) </xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$formData = $this->getRequest()->getPost();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>if ($form->isValid($formData)) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                
                <xsl:call-template name="getRecFormSave">
                    <xsl:with-param name="objectType" select="@name" />
                </xsl:call-template>
                
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$this->_helper->redirector('index');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>} else { </xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$form->populate($formData);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}//update</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>}//class</xsl:text>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template name="generateZendViews">
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType">
            <xsl:variable name="className" select="@name" />        
        <!-- Index.phtml -->
            <xsl:result-document href="{$filepath}application/views/scripts/{@name}/index.phtml" format="php">
                <xsl:text>&lt;p&gt;&lt;a href="&lt;?php echo $this->url(array('controller'=>'</xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text>','action'=>'add'));?&gt;">Add new </xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>&lt;/a&gt;&lt;/p&gt;</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;table&gt;&lt;tr&gt;</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:call-template name="getRecIndexTableHead">
                    <xsl:with-param name="objectType" select="@name"/>
                </xsl:call-template>
                <xsl:text>&lt;th&gt; &amp;nbsp; &lt;/th&gt;</xsl:text>
                <xsl:text>&lt;/tr&gt;</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>&lt;?php foreach($this-></xsl:text>
                <xsl:value-of select="@name"/>
                <xsl:text> as $row) { ?&gt;</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>&lt;tr&gt;</xsl:text>
                <xsl:call-template name="getRecIndexTableRow">
                    <xsl:with-param name="objectType" select="@name"/>
                    <xsl:with-param name="subObjectType" select="@name"/>
                </xsl:call-template>
                <xsl:text>&lt;td&gt; &lt;a href="&lt;?php echo $this->url(array(</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>'controller'=> '</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>', 'action'=>'edit', </xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>' => $row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>(), </xsl:text>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:variable name="superPrimary">
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="$superPrimary" />
                    <xsl:text>' => $row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($superPrimary)" />
                    <xsl:text>()</xsl:text>
                </xsl:if>
                <xsl:text>));?>">Edit&lt;/a></xsl:text>
                <xsl:text>&lt;/td&gt;</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>&lt;td&gt; &lt;a href="&lt;?php echo $this->url(array(</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>'controller'=> '</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>', 'action'=>'delete', </xsl:text>
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>' => $row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>(),</xsl:text>
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:variable name="superPrimary">
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>'</xsl:text>
                    <xsl:value-of select="$superPrimary" />
                    <xsl:text>' => $row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($superPrimary)" />
                    <xsl:text>()</xsl:text>
                </xsl:if>
                <xsl:text>));?>">Delete&lt;/a></xsl:text>
                <xsl:text>&lt;/td&gt;</xsl:text>
                <xsl:text>&lt;/tr&gt;</xsl:text>  
                <xsl:value-of select="$break" /> 
                <xsl:text>&lt;?php } ?&gt;</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;/table&gt;</xsl:text>
            </xsl:result-document>
        <!-- add.phtml -->
            <xsl:result-document href="{$filepath}application/views/scripts/{@name}/add.phtml" format="php">
                <xsl:text>&lt;?php echo $this->form ;?></xsl:text>
            </xsl:result-document>
        <!-- edit.phtml -->
            <xsl:result-document href="{$filepath}application/views/scripts/{@name}/edit.phtml" format="php">
                <xsl:text>&lt;?php echo $this->form ;?></xsl:text>
            </xsl:result-document>
        <!-- delete.phtml -->
            <xsl:result-document href="{$filepath}application/views/scripts/{@name}/delete.phtml" format="php">
                <xsl:text>&lt;p>Are you sure that you want to delete '</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:variable name="className"><xsl:value-of select="@name" /></xsl:variable>
                <xsl:for-each select="zfiml:Attribute">
                    <xsl:text>&lt;?php echo $this-></xsl:text>
                    <xsl:value-of select="$className" />
                    <xsl:text>->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>(); ?>' </xsl:text>
                    <xsl:value-of select="$break" />
                </xsl:for-each>
                <xsl:text>&lt;/p></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;form action="&lt;?php echo $this->url(array('action'=>'delete')); ?>" method="post"></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;div></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:for-each select="zfiml:Attribute[@isStandardID = 'true']">
                    <xsl:text>&lt;input type="hidden" name="</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>" value="&lt;?php echo $this-></xsl:text>
                    <xsl:value-of select="$className" />
                    <xsl:text>->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>(); ?>" /></xsl:text>
                    <xsl:value-of select="$break" />
                </xsl:for-each>
                <xsl:if test="@superType">
                    <xsl:variable name="superPrimary">
                        <xsl:call-template name="getPrimaryFromSuper">
                            <xsl:with-param name="objectType" select="@superType"/>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>&lt;input type="hidden" name="</xsl:text>
                    <xsl:value-of select="$superPrimary" />
                    <xsl:text>" value="&lt;?php echo $this-></xsl:text>
                    <xsl:value-of select="$className" />
                    <xsl:text>->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($superPrimary)" />
                    <xsl:text>(); ?>" /></xsl:text>
                    <xsl:value-of select="$break" />
                </xsl:if>
                <xsl:text>&lt;input type="submit" name="del" value="Yes" /></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;input type="submit" name="del" value="No" /></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;/div></xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>&lt;/form></xsl:text>
                <xsl:value-of select="$break" />            
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    
    <xsl:template name="generateZendForms">
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType">            
            <xsl:result-document href="{$filepath}application/forms/{@name}.php" format="php">
                <xsl:text>&lt;?php</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>class Application_Form_</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:if test="not(@superType)">
                    <xsl:text> extends Zend_Form</xsl:text>
                </xsl:if>
                <xsl:if test="@superType">
                    <xsl:text> extends Application_Form_</xsl:text>
                    <xsl:value-of select="@superType" />
                </xsl:if>
                <xsl:value-of select="$break" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>protected $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>;</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>public function __construct($</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:if test="@superType">
                    <xsl:text>, </xsl:text>
                    <xsl:call-template name="getRecParentNameList">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>)</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>{</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this-></xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text> = $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>;</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <!-- get Name of current Action -->
                <xsl:text>$actionName = Zend_Controller_Front::getInstance()->getRequest()->getActionName();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:variable name="className" select="@name" />
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                    | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text> = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)" />
                    <xsl:text>Tbl();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)" />
                    <xsl:text>Tbl();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
                
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>Tbl();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <!--  -->
                <xsl:if test="@superType">
                    <xsl:call-template name="getRecParentTableObjects">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab,$tab)" />
                
                <xsl:text>parent::__construct(</xsl:text>
                <xsl:if test="@superType">
                    <xsl:call-template name="getRecParentNameList">
                        <xsl:with-param name="objectType" select="@superType"/>
                    </xsl:call-template>
                </xsl:if>
                <xsl:text>);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->setName('</xsl:text>
                <xsl:value-of select="@name" />
                <xsl:text>');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:if test="@superType">
                    <xsl:text>//remove submitbutton of super for adding some new elements before</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->removeElement('submit');</xsl:text>
                </xsl:if>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:for-each select="zfiml:Attribute|zfiml:EnumerationProperty">
                    <xsl:if test="name()='zfiml:EnumerationProperty'">
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name"></xsl:value-of>
                        <xsl:text>Options = $</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(../@name)"></xsl:value-of>
                        <xsl:text>Tbl->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                        <xsl:text>Options();</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>foreach($</xsl:text>
                        <xsl:value-of select="@name"></xsl:value-of>
                        <xsl:text>Options as $row) {</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name"></xsl:value-of>
                        <xsl:text>Array[$row] = $row;</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>}</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text> = new Zend_Form_Element_Select('</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>');</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>->setMultiOptions($</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>Array)</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>->setValue($this-></xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(../@name)"></xsl:value-of>
                        <xsl:text>->get</xsl:text>
                        <xsl:value-of select="aorml:upperFirst(@name)" />
                        <xsl:text>());</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    <xsl:if test="name()='zfiml:Attribute'">
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text> = new Zend_Form_Element_Text('</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>');</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                    </xsl:if>
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>->setLabel('</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>')</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    
                    <!-- if attribute is required  -->
                    <xsl:if test="(not(@lowerMultiplicity) or (@lowerMultiplicity != '0'))">
                        <xsl:text>->setRequired(true)</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    
                <!-- add validators -->
                    <!-- if type is date add validator -->
                    <xsl:if test="@type = 'Date'">
                        <xsl:text>->addValidator('Date')</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is integer add validator -->
                    <xsl:if test="@type = 'Integer'">
                        <xsl:text>->addValidator('Int')</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is float add validator -->
                    <xsl:if test="@type = 'Float'">
                        <xsl:text>->addValidator('Float')</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is email add validator -->
                    <xsl:if test="@type = 'Email'">
                        <xsl:text>->addValidator(new Zend_Validate_EmailAddress(
                        Zend_Validate_Hostname::ALLOW_DNS ))</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is Boolean add validator -->
                    <xsl:if test="@type = 'Boolean'">
                        <xsl:text>->addValidator(new WebAOR_Validate_Boolean())</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is Time add validator -->
                    <xsl:if test="@type = 'Time'">
                        <xsl:text>->addValidator(new WebAOR_Validate_Time())</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is Datetime add validator -->
                    <xsl:if test="@type = 'DateTime'">
                        <xsl:text>->addValidator(new WebAOR_Validate_Datetime())</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is Tel add validator -->
                    <xsl:if test="@type = 'Tel'">
                        <xsl:text>->addValidator(new WebAOR_Validate_Tel())</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if type is Url add validator -->
                    <xsl:if test="@type = 'URL'">
                        <xsl:text>->addValidator(new Zend_Validate_Callback(array('Zend_Uri', 'check')))</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if minValue is set add validator -->
                    <xsl:if test="@minValue">
                        <xsl:text>->addValidator(new Zend_Validate_GreaterThan(array('min' => </xsl:text>
                        <xsl:value-of select="@minValue" />
                        <xsl:text>)))</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <!-- if maxValue is set add validator -->
                    <xsl:if test="@maxValue">
                        <xsl:text>->addValidator(new Zend_Validate_LessThan(array('max' => </xsl:text>
                        <xsl:value-of select="@maxValue" />
                        <xsl:text>)))</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    
                    <!-- validator against space-values -->
                    <xsl:text>->addValidator('NotEmpty');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    
                    <!-- for add-action test if key not in database -->
                    <xsl:if test="@isStandardID = 'true'">
                        <xsl:text>if($actionName == 'add')</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>->addValidator(new Zend_Validate_Db_NoRecordExists(array(</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                        <xsl:text>'table' => '</xsl:text>
                        <xsl:value-of select="aorml:upperFirst($className)" />
                        <xsl:text>', 'field' => '</xsl:text>
                        <xsl:value-of select="@name" />
                        <xsl:text>')));</xsl:text>
                        <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->addElement($</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>);</xsl:text>
                    <xsl:value-of select="$break" />
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
            
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                        | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array = array();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$marked</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)" />
                    <xsl:text> = array();</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>foreach($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>-&gt;fetchAll() as $row) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array[$row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>()] = </xsl:text>
                    <xsl:call-template name="getInfoPhrase">
                        <xsl:with-param name="objectType" select="@type" />
                        <xsl:with-param name="refKey" select="$refKey" />
                    </xsl:call-template>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <xsl:text>if($actionName!='add'){</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>foreach($this-&gt;</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst($className)" />
                    <xsl:text>-&gt;get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"/>
                    <xsl:text>s() as $row) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                    <xsl:text>array_push($marked</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)" />
                    <xsl:text> , $row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>());</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="$break" />
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text> = new Zend_Form_Element_Multiselect('</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text>', array(</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'label' =&gt; '</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)"/>
                    <xsl:text>', 'multiOptions' =&gt; $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array, </xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>'value' =&gt; $marked</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)" />
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>));</xsl:text>
                    <xsl:if test="not(@lowerMultiplicity)or(@lowerMultiplicity!='0')">
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)"/>
                        <xsl:text>->setRequired();</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->addElement($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text>);</xsl:text>
                    
                </xsl:for-each>
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab,$tab)" />
                
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array = array(''=>'');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <!-- get all keys from Type as array -->
                    <xsl:text>foreach($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Tbl-&gt;fetchAll() as $row) {</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array[$row->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>()] = </xsl:text>
                    <xsl:call-template name="getInfoPhrase">
                        <xsl:with-param name="objectType" select="@type" />
                        <xsl:with-param name="refKey" select="$refKey" />
                    </xsl:call-template>
                    <xsl:text>;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text> = new Zend_Form_Element_Select('</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)" />
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>->setMultiOptions($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)" />
                    <xsl:text>Array)</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>->setLabel('</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>');</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>if($actionName!='add'){</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    <xsl:text>$</xsl:text>
                    <xsl:value-of select="@name" />
                    <xsl:text>->setValue($this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(../@name)"></xsl:value-of>
                    <xsl:text>->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>()->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>());</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>}</xsl:text>
                    <xsl:if test="not(@lowerMultiplicity)or(@lowerMultiplicity!='0')">
                        <xsl:value-of select="concat($break,$tab,$tab)" />
                        <xsl:text>$</xsl:text>
                        <xsl:value-of select="aorml:lowerFirst(@name)"/>
                        <xsl:text>->setRequired();</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>$this->addElement($</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@name)"/>
                    <xsl:text>);</xsl:text>
                </xsl:for-each>
            
                <xsl:value-of select="$break" />
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$submit = new Zend_Form_Element_Submit('submit');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$submit->setAttrib('id', 'submitbutton');</xsl:text>   
                <xsl:value-of select="concat($break,$tab,$tab)" />
                <xsl:text>$this->addElement($submit);</xsl:text>
                <xsl:value-of select="concat($break,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="$break" />
                <xsl:text>}</xsl:text>
            </xsl:result-document>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="getPrimary">
        <xsl:param name="objectType"></xsl:param>
        <xsl:value-of select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]/zfiml:Attribute[@isStandardID = 'true']/@name"></xsl:value-of>
    </xsl:template>
    <xsl:template name="getDomainRole">
        <xsl:param name="association"></xsl:param>
        <xsl:param name="name"></xsl:param>
            <xsl:value-of select="/zfiml:ZFApplication/zfiml:ManyToManyAssociation[@name=$association]/zfiml:ZF-ReferenceProperty[@name != $name]/@name"></xsl:value-of>
    </xsl:template>
    <xsl:template name="getInfoPhrase">
        <xsl:param name="objectType"></xsl:param>
        <xsl:param name="refKey"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]/zfiml:Attribute[@isInfo = 'true']">
            <xsl:text>$row->get</xsl:text>
            <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
            <xsl:text>()</xsl:text>
            <xsl:if test="position() != last()">
                <xsl:text>.'-'.</xsl:text>
            </xsl:if>
        </xsl:for-each>
        <xsl:if test="not(/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]/zfiml:Attribute[@isInfo = 'true'])">
            <xsl:text>$row->get</xsl:text>
            <xsl:value-of select="aorml:upperFirst($refKey)"></xsl:value-of>
            <xsl:text>()</xsl:text>
        </xsl:if>
    </xsl:template>
    <xsl:template name="getIndexInfoPhrase">
        <xsl:param name="objectType"></xsl:param>
        <xsl:param name="refKey"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]/zfiml:Attribute[@isInfo = 'true']">
            <xsl:text>$item->get</xsl:text>
            <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
            <xsl:text>()</xsl:text>
            <xsl:if test="position() != last()">
                <xsl:text>.'-'.</xsl:text>
            </xsl:if>
        </xsl:for-each>
        <xsl:if test="not(/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]/zfiml:Attribute[@isInfo = 'true'])">
            <xsl:text>$item->get</xsl:text>
            <xsl:value-of select="aorml:upperFirst($refKey)"></xsl:value-of>
            <xsl:text>()</xsl:text>
        </xsl:if>
    </xsl:template>
    
    <xsl:template name="getFormUpdate">
        <xsl:param name="objectType" />
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="@superType">
                <xsl:variable name="superPrimary">
                    <xsl:call-template name="getPrimaryFromSuper">
                        <xsl:with-param name="objectType" select="@superType" />
                    </xsl:call-template>
                </xsl:variable>
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst($objectType)" />
                <xsl:text>->set</xsl:text>
                <xsl:value-of select="aorml:upperFirst($superPrimary)"></xsl:value-of>
                <xsl:text>($form->getValue('</xsl:text>
                <xsl:value-of select="$superPrimary"></xsl:value-of>
                <xsl:text>'));</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
            </xsl:if>
            <xsl:for-each select="zfiml:Attribute|zfiml:EnumerationProperty">
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst($objectType)" />
                <xsl:text>->set</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                <xsl:text>($form->getValue('</xsl:text>
                <xsl:value-of select="@name"></xsl:value-of>
                <xsl:text>'));</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
            </xsl:for-each>
            <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text>->save();</xsl:text>
            <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
            <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                    | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)
                                        or(@viaManyToManyAssociation='false'))
                                        and @upperMultiplicity='unbounded' ]">
                <xsl:variable name="refKey">
                    <xsl:call-template name="getPrimary">
                        <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                    </xsl:call-template>
                </xsl:variable>
                <xsl:text>$selected</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text> = $form->getValue('</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>');</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$old</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text> = array();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>$new</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text> = array();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    
                <xsl:text>foreach($</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>-&gt;get</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>s() as $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$old</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>[$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>-&gt;get</xsl:text>
                <xsl:value-of select="aorml:upperFirst($refKey)" />
                <xsl:text>()] = $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>-&gt;get</xsl:text>
                <xsl:value-of select="aorml:upperFirst($refKey)" />
                <xsl:text>();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    
                <xsl:text>foreach($selected</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text> as $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$new</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>[$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>] = $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>;</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>if (!isset($old</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>[$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>])) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>-&gt;add</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>($this-></xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@type)"/>
                <xsl:text>Tbl-&gt;get</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@type)"/>
                <xsl:text>Object($</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>));</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                    
                <xsl:text>foreach($old</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text> as $</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>if (!isset($new</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>[$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>])) {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>-&gt;remove</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>($this-></xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@type)"/>
                <xsl:text>Tbl-&gt;get</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@type)"/>
                <xsl:text>Object($</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>));</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
            </xsl:for-each>
            <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) 
                                    or @upperMultiplicity = '1')
                                        and (not(@derived) or (@derived = 'false'))]">                    
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>if(trim($form->getValue('</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>'))!=''){</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>->set</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>($this-></xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@type)" />
                <xsl:text>Tbl->get</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@type)" />
                <xsl:text>Object($form->getValue('</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:text>')));</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>->save();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:text> else {</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>->set</xsl:text>
                <xsl:value-of select="aorml:upperFirst(@name)" />
                <xsl:text>(null);</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab,$tab)" />
                <xsl:text>$</xsl:text>
                <xsl:value-of select="aorml:lowerFirst(../@name)" />
                <xsl:text>->save();</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>}</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
            </xsl:for-each>   
        </xsl:for-each>
    </xsl:template>
    
    <!-- =================================================================== -->
    <!-- functions for generate Generalization -->
    <!-- =================================================================== -->
    <!-- generates recursive a List of superclass-names lowerCase -->
    <xsl:template name="getRecParentNameList">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$</xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:if test="@superType">
                <xsl:text>, </xsl:text>
                <xsl:call-template name="getRecParentNameList">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- generates recursive Table objects from superclass -->
    <xsl:template name="getRecParentTableObjects">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$</xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
            <xsl:value-of select="aorml:upperFirst(@name)" />
            <xsl:text>Tbl();</xsl:text>
            <xsl:value-of select="concat($break,$tab,$tab)" />
            <xsl:if test="@superType">
                <xsl:call-template name="getRecParentTableObjects">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- recursiv get the primary from superclass -->
    <xsl:template name="getPrimaryFromSuper">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="not(@superType)">
                <xsl:value-of select="zfiml:Attribute[@isStandardID = 'true']/@name" />
            </xsl:if>
            <xsl:if test="@superType">
                <xsl:call-template name="getPrimaryFromSuper">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- recursiv get referenceMap from superclass -->
    <xsl:template name="getReferenceMapFromSuper">
        <xsl:param name="objectType"></xsl:param>
        <xsl:param name="directSuperType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="not(@superType)">
                <xsl:text>'</xsl:text>
                <xsl:value-of select="aorml:upperFirst($directSuperType)" />
                <xsl:text>' => array(</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>'columns' => '</xsl:text>
                <xsl:value-of select="zfiml:Attribute[@isStandardID = 'true']/@name" />
                <xsl:text>',</xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>'refTableClass' => 'Application_Model_DbTable_</xsl:text>
                <xsl:value-of select="aorml:upperFirst($directSuperType)" />
                <xsl:text>Tbl', </xsl:text>
                <xsl:value-of select="concat($break,$tab,$tab,$tab)" />
                <xsl:text>'refColumn' => '</xsl:text>
                <xsl:value-of select="zfiml:Attribute[@isStandardID = 'true']/@name" />
                <xsl:text>')</xsl:text>
                
            </xsl:if>
            <xsl:if test="@superType">
                <xsl:call-template name="getReferenceMapFromSuper">
                    <xsl:with-param name="objectType" select="@superType" />
                    <xsl:with-param name="directSuperType" select="$directSuperType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- recursiv get table-objects from superclass -->
    <xsl:template name="getSuperTableObjects">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$this-></xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
            <xsl:value-of select="aorml:upperFirst(@name)" />
            <xsl:text>Tbl();</xsl:text>
            <xsl:value-of select="$break" />
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                    | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"/>
                    <xsl:text>Tbl();</xsl:text>                    
                    <xsl:value-of select="$break" />                    
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:text>$this-></xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                    <xsl:text>Tbl = new Application_Model_DbTable_</xsl:text>
                    <xsl:value-of select="aorml:upperFirst(@type)"/>
                    <xsl:text>Tbl();</xsl:text>                    
                    <xsl:value-of select="$break" />                    
                </xsl:for-each>
            <xsl:if test="@superType">
                <xsl:call-template name="getSuperTableObjects">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    <!-- recursiv row-objects from superclass -->
    <xsl:template name="getRowsFromSuper">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$</xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text> = $this-></xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text>Tbl->createRow();</xsl:text>
            <xsl:if test="@superType">
                <xsl:call-template name="getRowsFromSuper">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- recursiv get a list from superclass -->
    <xsl:template name="getSuperTableObjectList">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>, $</xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                    | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:text>, $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:text>, $</xsl:text>
                    <xsl:value-of select="aorml:lowerFirst(@type)"/>
                </xsl:for-each>
            <xsl:if test="@superType">
                <xsl:call-template name="getSuperTableObjects">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- recursiv get Objects from superclass -->
    <xsl:template name="getRelatedSuperObjects">
        <xsl:param name="objectType"></xsl:param>
        <xsl:param name="subType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$</xsl:text>
            <xsl:value-of select="aorml:lowerFirst($objectType)" />
            <xsl:text> = $</xsl:text>
            <xsl:value-of select="aorml:lowerFirst($subType)" />
            <xsl:text>->get</xsl:text>
            <xsl:value-of select="aorml:upperFirst($objectType)" />
            <xsl:text>();</xsl:text>
            <xsl:value-of select="$break" />
            <xsl:if test="@superType">
                <xsl:call-template name="getRelatedSuperObjects">
                    <xsl:with-param name="objectType" select="@superType" />
                    <xsl:with-param name="subType" select="@name" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    
    <!-- generates recursive a List of Arrays of superclasses -->
    <xsl:template name="getSuperArrays">
        <xsl:param name="objectType"></xsl:param>
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:text>$</xsl:text>
            <xsl:value-of select="aorml:lowerFirst(@name)" />
            <xsl:text>->toArray()</xsl:text>
            <xsl:if test="@superType">
                <xsl:text>, </xsl:text>
                <xsl:call-template name="getSuperArrays">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="getRecFormSave">
        <xsl:param name="objectType" />
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="@superType">
                <xsl:call-template name="getRecFormSave">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
            <xsl:call-template name="getFormUpdate">
                <xsl:with-param name="objectType" select="$objectType" />
            </xsl:call-template>            
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="getRecIndexTableHead">
        <xsl:param name="objectType" />
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="@superType">
                <xsl:call-template name="getRecIndexTableHead">
                    <xsl:with-param name="objectType" select="@superType" />
                </xsl:call-template>
            </xsl:if>
            <xsl:for-each select="zfiml:Attribute|zfiml:EnumerationProperty">
                <xsl:text>&lt;th&gt;</xsl:text>
                <xsl:value-of select="@name"></xsl:value-of>
                <xsl:text>&lt;/th&gt;</xsl:text>
            </xsl:for-each>
            <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                            | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)
                            or(@viaManyToManyAssociation='false'))
                                        and @upperMultiplicity='unbounded' ]">
                <xsl:text>&lt;th&gt;</xsl:text>
                <xsl:value-of select="@name"></xsl:value-of>
                <xsl:text>s&lt;/th&gt;</xsl:text>
            </xsl:for-each>
            <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                    and (not(@derived) or (@derived = 'false'))]">
                <xsl:text>&lt;th&gt;</xsl:text>
                <xsl:value-of select="@name"></xsl:value-of>
                <xsl:text>&lt;/th&gt;</xsl:text>
            </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
    <xsl:template name="getRecIndexTableRow">
        <xsl:param name="objectType" />
        <xsl:param name="subObjectType" />
        <xsl:for-each select="/zfiml:ZFApplication/zfiml:ObjectType[@name=$objectType]">
            <xsl:if test="@superType">
                <xsl:call-template name="getRecIndexTableRow">
                    <xsl:with-param name="objectType" select="@superType" />
                    <xsl:with-param name="subObjectType" select="$objectType" />
                </xsl:call-template>
            </xsl:if>
            <xsl:for-each select="zfiml:Attribute|zfiml:EnumerationProperty">
                    <xsl:text>&lt;td&gt; &lt;?php echo $this->escape($row->get</xsl:text>
                    <xsl:if test="$objectType != $subObjectType">
                        <xsl:value-of select="aorml:upperFirst($objectType)" />
                        <xsl:text>()->get</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>()); ?&gt;&lt;/td&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[@viaManyToManyAssociation]
                                        | zfiml:ZF-ReferenceProperty[(not(@viaManyToManyAssociation)or(@viaManyToManyAssociation='false'))
                                                and @upperMultiplicity='unbounded' ]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:text>&lt;td&gt; &lt;select multiple='multiple' size='2' &gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>&lt;?php foreach($row->get</xsl:text>
                    <xsl:if test="$objectType != $subObjectType">
                        <xsl:value-of select="aorml:upperFirst($objectType)" />
                        <xsl:text>()->get</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="aorml:upperFirst(@name)" />
                    <xsl:text>s() as $item) {?&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>&lt;option title="&lt;?php echo $this->escape($item->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>()) ?&gt;" &gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>&lt;?php echo $this->escape(</xsl:text>
                    <xsl:call-template name="getIndexInfoPhrase">
                        <xsl:with-param name="objectType" select="@type" />
                        <xsl:with-param name="refKey" select="$refKey" />
                    </xsl:call-template>
                    <xsl:text>) ?&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab,$tab)" />
                    <xsl:text>&lt;/option&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>&lt;?php } ?&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>&lt;/select&gt;&lt;/td&gt;</xsl:text>
                </xsl:for-each>
                <xsl:for-each select="zfiml:ZF-ReferenceProperty[(not(@upperMultiplicity) or @upperMultiplicity = '1')
                        and (not(@derived) or (@derived = 'false'))]">
                    <xsl:variable name="refKey">
                        <xsl:call-template name="getPrimary">
                            <xsl:with-param name="objectType" select="@type"></xsl:with-param>
                        </xsl:call-template>
                    </xsl:variable>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>&lt;td&gt; &lt;?php if($row->get</xsl:text>
                    <xsl:if test="$objectType != $subObjectType">
                        <xsl:value-of select="aorml:upperFirst($objectType)" />
                        <xsl:text>()->get</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>())</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                    <xsl:text>echo $this->escape($row->get</xsl:text>
                    <xsl:if test="$objectType != $subObjectType">
                        <xsl:value-of select="aorml:upperFirst($objectType)" />
                        <xsl:text>()->get</xsl:text>
                    </xsl:if>
                    <xsl:value-of select="aorml:upperFirst(@name)"></xsl:value-of>
                    <xsl:text>()->get</xsl:text>
                    <xsl:value-of select="aorml:upperFirst($refKey)" />
                    <xsl:text>()); ?&gt;&lt;/td&gt;</xsl:text>
                    <xsl:value-of select="concat($break,$tab)" />
                </xsl:for-each>
        </xsl:for-each>
    </xsl:template>
</xsl:stylesheet>